<template>
    <a-spin :spinning="confirmLoading">
      <j-form-container :disabled="formDisabled">
        <a-form :form="form" slot="detail">
          <a-row>
              <a-col :span="24">
                <a-form-item label="">
                  <div class="jcblbox">
                    <!-- <a-checkbox v-model="model.markupRatioFlag">
                      加成比例：
                    </a-checkbox> -->
                    <a-input-number style="width: 100%;" :min="0" v-decorator="['singleCommission',{rules:[ { required: true, message: '请输入!'}]}]" placeholder="请输入"></a-input-number>

                  </div>
                  
                </a-form-item>
              </a-col>  
             
          </a-row>
         
        </a-form>
      </j-form-container>
    </a-spin>
  </template>
  
  <script>
  
    import { httpAction, getAction } from '@/api/manage'
    import pick from 'lodash.pick'
    import { validateDuplicateValue } from '@/utils/util'
    import JFormContainer from '@/components/jeecg/JFormContainer'
    import JSwitch from '@/components/jeecg/JSwitch'
    import JDate from '@/components/jeecg/JDate'  
    import JSelectInput from '@comp/jeecgbiz/JSelectInput'
    import lodash from 'lodash'
    export default {
      name: 'setPriceForm',
      components: {
        JFormContainer,
        JDate,
        JSwitch,
        JSelectInput
      },
      props: {
        //流程表单data
        formData: {
          type: Object,
          default: ()=>{},
          required: false
        },
        //表单模式：true流程表单 false普通表单
        formBpm: {
          type: Boolean,
          default: false,
          required: false
        },
        //表单禁用
        disabled: {
          type: Boolean,
          default: false,
          required: false
        }
      },
      data () {
        return {
          validatorRules: {

            stockLimitUp:{
              rules: [{validator: this.compareStockLimitUp}]
            }
          },
          yibaobotshow:false,
          keywords:'',
          yibaoswitch:'N',
          ybdz:false,
          form: this.$form.createForm(this),
          model: {},
          
          labelCol: {
            lg: { span: 8 },
            xxl: { span: 6 },
          },
          wrapperCol: {
            lg: { span: 16 },
            xxl: { span: 16 },
          },
          confirmLoading: false,
         
          url: {
            edit: "",
            queryById: "/wh/drugWestern/detail"
          }
        }
      },
      computed: {
        formDisabled(){
          if(this.formBpm===true){
            if(this.formData.disabled===false){
              console.log('000000');
              this.keywords = '';
              return false
            }
            return true
          }
          return this.disabled
        },
        showFlowSubmitButton(){
          if(this.formBpm===true){
            if(this.formData.disabled===false){
              return true
            }
          }
          return false
        }
      },
      mounted () {
        console.log('456');
       
      },
      methods: {
        validateStockLimitDown  (rule, value, callback) {
          const form = this.form;
          const stockLimitUp=form.getFieldValue('stockLimitUp');

          if (value >= stockLimitUp) {
            callback('下限不能大于上限！');
          }
          if (value) {
            form.validateFields(['stockLimitUp'], { force: true })
          }
          callback();
        },
        compareStockLimitUp  (rule, value, callback) {
          const form = this.form;
          if (value <= form.getFieldValue('stockLimitDown')) {
            // callback('上限不能小于下限！');
            callback('下限不能大于上限！');
          }else {
            callback()
          }
        },
       
        add () {
          this.edit({});
        },
        edit (record) {
          this.form.resetFields();
          this.model = Object.assign({}, record);
          this.visible = true;
          this.$nextTick(() => {
            this.form.setFieldsValue(pick(this.model,'singleCommission','markupRatioFlag'))

          })
        },
        
        submitForm () {
          const that = this;
          // 触发表单验证
          this.form.validateFields((err, values) => {
            if (!err) {
              that.confirmLoading = true;
              let httpurl = '';
              let method = 'put';
              let formData = Object.assign({}, values);
              formData.id = this.model.id
              formData.markupRatioFlag = this.model.markupRatioFlag?1:0
              switch (this.model.project+'') {
                case '1':
                  httpurl = '/wh/drugWestern/adjustmentSingleCommission'
                  break;
                case '2':
                  httpurl = '/wh/drugChinese/adjustmentSingleCommission'
                  break;
                case '3':
                  httpurl = '/wh/medicalConsumable/adjustmentSingleCommission'
                  break;
                case '4':
                  httpurl = '/wh/medicalServiceProject/adjustmentSingleCommission'
                  break;
              }
              console.log("表单提交数据",formData)
              httpAction(httpurl,formData,method).then((res)=>{
                if(res.success){
                  that.$message.success(res.message);
                  that.$emit('ok');
                }else{
                  that.$message.warning(res.message);
                }
              }).finally(() => {
                that.confirmLoading = false;
              })
            }
           
          })
        },
      
      }
    }
  </script>
  <style lang="less" scoped>
  .yb-form{
    background: #F0F0F0;
    padding: 12px;
  }
  </style>